/*
 *
 */ 

package edu.uoc.tdp.pac4.client.pantalles;

import edu.uoc.tdp.pac4.client.ClientRMI;
import edu.uoc.tdp.pac4.client.S3ClientRMI;
import edu.uoc.tdp.pac4.common.utils.*;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
//import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableRowSorter;
import javax.swing.table.TableCellRenderer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PrinterException;
import java.awt.event.ActionListener;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
//import java.awt.List;
import java.util.Locale;
import java.util.Date;
import java.util.List;

import edu.uoc.tdp.pac4.common.beans.PecaReparacio;
import edu.uoc.tdp.pac4.common.beans.Reparacio;
import edu.uoc.tdp.pac4.common.beans.Reparacio.Estat;
import edu.uoc.tdp.pac4.common.beans.S1Usuari;
import edu.uoc.tdp.pac4.common.beans.S3Client;
import edu.uoc.tdp.pac4.common.beans.S3MarcaCotxe;
import edu.uoc.tdp.pac4.common.beans.S3PecaReparacio;
import edu.uoc.tdp.pac4.common.exception.ExcepcioClientRMI;
import edu.uoc.tdp.pac4.common.exception.ExcepcioConnexioBD;
import edu.uoc.tdp.pac4.common.exception.S3ExcepcioPecaReparacio;
import edu.uoc.tdp.pac4.common.exception.S3ExcepcioReparacio;
import edu.uoc.tdp.pac4.common.exception.S3ExcepcioStockPeca;
import edu.uoc.tdp.pac4.common.exception.S3SmartRepairException;
import edu.uoc.tdp.pac4.common.interfaces.S3Interface;
import edu.uoc.tdp.pac4.common.utils.TDSLanguageUtils;


public class S3PantallaReparacions extends JPanel implements ActionListener {
	
    private boolean DEBUG = false;
    private JTable table;
    private JTextField textFiltre;
    private JTextField statusText;
    private TableRowSorter<MyTableModel> sorter;
    private S3Interface objecteRemot;
    private List<Reparacio> llistaReparacions;
    private MyTableModel model;
    private Object[][] data;
    private int columnfil = 0;
    private JLabel labelConte;
    private JButton btnActualitzar;
    private JButton btnDetall;
    private JButton btnAcceptar;
    private JButton btnAssignar;    
    private JButton btnFinalitzar;       
    private JButton btnSortir;           
 	private JFrame frameReparacions;
 	
 	private final String NL = System.getProperty("line.separator");
	private JPanel panelReparacions;
	private JPanel panelCerca;
	private ComboBoxReparacions comboCerca;
	private JLabel labelSeparacio;
	private S3PantallaDetallReparacio pantDetallReparacio;
	private S3PantallaPecesReparacio pantPecesReparacio;
	private S1Usuari usuari;
	private AbstractButton btnDenegar;
	private S1PanelInicial panelInicial;
	private ClientRMI remotS1;
	private int tipusCarrega;
	
   public S3PantallaReparacions(JFrame pFrame, S3Interface objRemot, S1Usuari usu)   {
     	 
	    frameReparacions = pFrame;
        objecteRemot = objRemot;
        usuari = usu;
     	
     	//Panel principal
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        
        //Panel cerca
        panelCerca = new JPanel(new SpringLayout());
        panelCerca.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE),TDSLanguageUtils.getMessage("REPARACIONS_CERCA_TITOL")));
        comboCerca = new ComboBoxReparacions();
        panelCerca.add(comboCerca);
        labelConte = new JLabel(TDSLanguageUtils.getMessage("REPARACIONS_CERCA_CONTE"));
        labelConte.setVisible(false);
        panelCerca.add(labelConte);
        textFiltre = new JTextField();
        textFiltre.setVisible(false);
        textFiltre.setPreferredSize(new Dimension(500,textFiltre.getSize().height));
        panelCerca.add(textFiltre);
        
        textFiltre.getDocument().addDocumentListener(
                new DocumentListener() {
                    public void changedUpdate(DocumentEvent e) {
                        newFilter();
                    }
                    public void insertUpdate(DocumentEvent e) {
                        newFilter();
                    }
                    public void removeUpdate(DocumentEvent e) {
                        newFilter();
                    }
                });
   
        add(panelCerca);
        SpringUtilities.makeCompactGrid(panelCerca, 1, 3, 6, 6, 6, 6);
        

        //Panel llista de reparacions
        model = new MyTableModel();
        tipusCarrega=0;
        carregaTaulaReparacions(tipusCarrega);
        sorter = new TableRowSorter<MyTableModel>(model);
        table = new JTable(model);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
      	rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
      	DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
      	centerRenderer.setHorizontalAlignment(JLabel.CENTER);
      	DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer();
      	leftRenderer.setHorizontalAlignment(JLabel.LEFT);
    	table.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(1).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(2).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(3).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(4).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(5).setCellRenderer(centerRenderer);
    	table.getColumnModel().getColumn(6).setCellRenderer(leftRenderer);
    	table.getColumnModel().getColumn(7).setCellRenderer(centerRenderer);
        table.setShowGrid(false);
       	JTableHeader header = table.getTableHeader();
    	header.setBackground(Color.cyan);
        table.setRowSorter(sorter);
        table.setPreferredScrollableViewportSize(new Dimension(1000, 200));
        table.setFillsViewportHeight(true);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
          table.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent event) {
                        int viewRow = table.getSelectedRow();
                        if (viewRow < 0) {
                          	btnDetall.setEnabled(false);
                          	btnAcceptar.setEnabled(false);
                        	btnDenegar.setEnabled(false);
                        } else {
                            if (table.getValueAt(viewRow, 7).equals("PDT_ACCEPTAR")){
                              	btnAcceptar.setEnabled(true);
                            	btnDenegar.setEnabled(true);
                            }else{
                            	btnAcceptar.setEnabled(false);
                            	btnDenegar.setEnabled(false);
                            }
                            if (table.getValueAt(viewRow, 7).equals("ACCEPTADA")){
                            	btnAssignar.setEnabled(true);
                            }else{
                            	btnAssignar.setEnabled(false);
                            }
                            btnDetall.setEnabled(true);
                        }
                    }
                }
        );

        JScrollPane scrollPane = new JScrollPane(table);
        JPanel form2 = new JPanel(new SpringLayout());
        form2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE),TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_TITOL")));
        form2.add(scrollPane);
        add(form2);
        SpringUtilities.makeCompactGrid(form2, 1, 1, 6, 6, 6, 6);
         
        //Panel botons
        JPanel pnlBotons = new JPanel(new SpringLayout());
        //pnlBotons.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.ORANGE), "Accions"));
        btnActualitzar = new JButton();
        btnActualitzar.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ACTUALITZAR"));
        pnlBotons.add(btnActualitzar);
        btnActualitzar.addActionListener(this);       
        btnDetall = new JButton();
        btnDetall.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_DETALL"));
        btnDetall.setEnabled(false);
        pnlBotons.add(btnDetall);
        btnDetall.addActionListener(this);  
        btnAcceptar = new JButton();
        btnAcceptar.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ACCEPTAR"));
        pnlBotons.add(btnAcceptar);
        btnAcceptar.setEnabled(false);
        btnAcceptar.addActionListener(this);  
        btnDenegar = new JButton();
        btnDenegar.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_DENEGAR"));
        pnlBotons.add(btnDenegar);
        btnDenegar.setEnabled(false);
        btnDenegar.addActionListener(this);  
        btnAssignar = new JButton();
        btnAssignar.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ASSIGNAR"));
        pnlBotons.add(btnAssignar);
        btnAssignar.setEnabled(false);
        btnAssignar.addActionListener(this);  
        /*
        btnFinalitzar = new JButton();
        btnFinalitzar.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_FINALITZAR"));
        btnFinalitzar.setEnabled(false);
        pnlBotons.add(btnFinalitzar);
        btnFinalitzar.addActionListener(this);
        */  
        btnSortir = new JButton();
        btnSortir.setText(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_SORTIR"));
        pnlBotons.add(btnSortir);        
        btnSortir.addActionListener(this);  
        add(pnlBotons);
        SpringUtilities.makeCompactGrid(pnlBotons, 1, 6, 6, 6, 20, 6);
       
    }
   
   
   
   
   private class ComboBoxReparacions extends JComboBox  implements ActionListener {
  		
 		private ComboBoxReparacions() {
  
 			super();
 			 			
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_TOTES"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_PDT_ACCEPTAR"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ACCEPTADA"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ORDRE_REPARACIO"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_DATA_ENTRADA"));					
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_CONT_MINUTS"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MATRICULA"));					
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MARCA"));					
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MODEL"));
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_OBSERVACIONS"));					
 			addItem(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ESTAT"));					
 			
  			addActionListener(this);
 		}
 		
 		public void actionPerformed(ActionEvent e) {
  			String colNom = (String)comboCerca.getSelectedItem();
  			
   			if (colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_TOTES"))){
   				tipusCarrega=0;
   				carregaTaulaReparacions(tipusCarrega);
 				labelConte.setVisible(false);
 				textFiltre.setText(null);
 				textFiltre.setVisible(false);
  			}
   			if (colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_PDT_ACCEPTAR"))){
   				tipusCarrega=1;
   				carregaTaulaReparacions(tipusCarrega);
 				labelConte.setVisible(false);
 				textFiltre.setText(null);
 				textFiltre.setVisible(false);
  			}
   			if (colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ACCEPTADA"))){
   				tipusCarrega=2;
   				carregaTaulaReparacions(tipusCarrega);
 				labelConte.setVisible(false);
 				textFiltre.setText(null);
 				textFiltre.setVisible(false);
  			}
 			if (colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ORDRE_REPARACIO"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 0;
 			}
 			else if (colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_DATA_ENTRADA"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 1;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_CONT_MINUTS"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 2;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MATRICULA"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 3;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MARCA"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 4;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MODEL"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 5;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_OBSERVACIONS"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 6;
 			}
 			else if(colNom.equals(TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ESTAT"))){
 				labelConte.setVisible(true);
 				textFiltre.setText(null);
 				textFiltre.setVisible(true);
 				columnfil = 7;
 			}			
 		
  		}
     }
   
   
 		    
 	 class MiRender extends DefaultTableCellRenderer
 	  {
 	      public Component getTableCellRendererComponent(JTable table,
 	          Object value,
 	          boolean isSelected,
 	          boolean hasFocus,
 	          int row,
 	          int column)
 		       {
 		          super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
 		          //if ( ....)
 		          {
 		             //this.setOpaque(true);
 		             //this.setBackground(Color.RED);
 		             //this.setForeground(Color.YELLOW);
 		             //this.setBorder(BorderFactory.createLineBorder(Color));
 		          }
 		          return this;
 		       }
 	 }
  
  
    private void newFilter() {
        RowFilter<MyTableModel, Object> rf = null;
  
        try {
        	
            rf = RowFilter.regexFilter(textFiltre.getText(), columnfil);
        } catch (java.util.regex.PatternSyntaxException e) {
            return;
        }
        sorter.setRowFilter(rf);
    }

    private void carregaTaulaReparacions(int tipusCarrega) {
		
    	
		try{
			if (tipusCarrega == 0){
				llistaReparacions = objecteRemot.getReparacionsTallerLst(usuari.getTaller(),0,0);
			}else if (tipusCarrega == 1){
				llistaReparacions = objecteRemot.getReparacionsTallerLst(usuari.getTaller(),1,0);
			}else {
				llistaReparacions = objecteRemot.getReparacionsTallerLst(usuari.getTaller(),0,1);
			}
			
			data = new Object[llistaReparacions.size()][model.getColumnCount()];
			int fila = 0;
			
			for(Reparacio reparacio:llistaReparacions){
				data[fila][0] = reparacio.getOrdreReparacio();
				if (reparacio.getDataAlta()==null){
					data[fila][1] = "";
				}else {
					data[fila][1] = reparacio.getDataAlta().toString();
				}
				data[fila][2] = (int)reparacio.getComptador();
				S3Client client = objecteRemot.getClientPerId(reparacio.getNumClient());
				data[fila][3] = (String)client.getMatriculaCotxe(); 
				S3MarcaCotxe marca = objecteRemot.getMarcaCotxetPerId(client.getIdmarca());
				data[fila][4] = marca.getNom();
				data[fila][5] = client.getModelCotxe();
				data[fila][6] = reparacio.getObservacions();
				data[fila][7] = reparacio.getEstat().toString();
				fila++;
			} 	
		
			//if (data.length == 0){
				//model.fireTableRowsDeleted(0, 0);
			//}else {
			model.fireTableDataChanged();
			//}
	
		}
		catch (RemoteException e){
			JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("ERROR_REMOT") 
							+ NL + e.getMessage(), "SmartRepair", JOptionPane.ERROR_MESSAGE);
		}
		catch (Exception e){
			JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("ERROR_EXCEPTION")
							+ NL  +e.getMessage(), "SmartRepair", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}
		
	}


    class MyTableModel extends AbstractTableModel {
        private String[] columnNames = {
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ORDRE_REPARACIO"),        		
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_DATA_ENTRADA"),
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_CONT_MINUTS"),
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MATRICULA"),
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MARCA"),
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_MODEL"),
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_OBSERVACIONS"),        	
        	TDSLanguageUtils.getMessage("REPARACIONS_LLISTA_ESTAT"),
           };
        
        
        public MyTableModel(){
        	
        }
        
        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        /*
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
        */

    
        public boolean isCellEditable(int row, int col) {
   
            if (col < 8) {
                return false;
            } else {
                return true;
            }
        }

   
        public void setValueAt(Object value, int row, int col) {
            if (DEBUG) {
                System.out.println("Setting value at " + row + "," + col
                                   + " to " + value
                                   + " (an instance of "
                                   + value.getClass() + ")");
            }

            data[row][col] = value;
            fireTableCellUpdated(row, col);

            if (DEBUG) {
                System.out.println("New value of data:");
                printDebugData();
            }
        }

        private void printDebugData() {
            int numRows = getRowCount();
            int numCols = getColumnCount();

            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                    System.out.print("  " + data[i][j]);
                }
                System.out.println();
            }
            System.out.println("--------------------------");
        }
    }
    
  

    
    public void actionPerformed(ActionEvent e) {
    	
   
       if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ACTUALITZAR"))) {
     	    carregaTaulaReparacions(tipusCarrega);
 
       } else if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_DETALL"))) {
            int seleccio = table.getSelectedRow();
            for(Reparacio reparacio:llistaReparacions){
            	if (table.getValueAt(seleccio,0).equals(reparacio.getOrdreReparacio())){
            		S3PantallaDetallReparacio pantDetallReparacio = new S3PantallaDetallReparacio(frameReparacions, objecteRemot, usuari, reparacio);
            		break;
            	}
            }
            
        } else if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ACCEPTAR"))) {
            int seleccio = table.getSelectedRow();
            for(Reparacio reparacio:llistaReparacions){
            	if (table.getValueAt(seleccio,0).equals(reparacio.getOrdreReparacio())){
       		         pantPecesReparacio = new S3PantallaPecesReparacio(frameReparacions, objecteRemot, usuari, reparacio);
               		 break;
            	}
            }
            
        } else if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_DENEGAR"))) {
        	 int seleccio = table.getSelectedRow();
          	try {
              for(Reparacio reparacio:llistaReparacions){
             	if (table.getValueAt(seleccio,0).equals(reparacio.getOrdreReparacio())){
             		reparacio.setEstat(Estat.REBUTJADA);
    				objecteRemot.setReparacio(reparacio);
    				JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("REPARACIONS_MISSATGES_REP_DENEGADA"),
    						"SmartRepair", JOptionPane.INFORMATION_MESSAGE);
    				carregaTaulaReparacions(tipusCarrega);
            		break;
            	}
              }     	    
			} catch (RemoteException e1) {
				e1.printStackTrace();
			} catch (ExcepcioConnexioBD e1) {
				e1.printStackTrace();
			} catch (S3ExcepcioReparacio e1) {
				e1.printStackTrace();
			}
        } else if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_ASSIGNAR"))) {
        	int seleccio = table.getSelectedRow();
            for(Reparacio reparacio:llistaReparacions){
           	   if (table.getValueAt(seleccio,0).equals(reparacio.getOrdreReparacio())){
           		    List<S3PecaReparacio> llistaPecesRep;
           		    boolean stockInsuficient = false;
					try {
						llistaPecesRep = objecteRemot.getPecesReparacioLst(reparacio.getOrdreReparacio());
						for(S3PecaReparacio pecareparacio:llistaPecesRep){
							if ((objecteRemot.getStockPeca(pecareparacio.getCodiPeca()) < pecareparacio.getQuantitat())){
								stockInsuficient = true;
							}
		           		}
					} catch (RemoteException e1) {
							e1.printStackTrace();
					} catch (ExcepcioConnexioBD e1) {
							e1.printStackTrace();
					} catch (S3ExcepcioPecaReparacio e1) {
							e1.printStackTrace();
			   		} catch (S3ExcepcioStockPeca e1) {
			   				e1.printStackTrace();
			   		}
					if (!stockInsuficient){
	                     S3PantallaAssignacioMecanic pantAssignacioMecanic = new S3PantallaAssignacioMecanic(frameReparacions, objecteRemot, usuari, reparacio);
					}else {
	                	JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("REPARACIONS_MISSATGES_ERROR_STOCK_INSUFICIENT"),
	    						"SmartRepair", JOptionPane.ERROR_MESSAGE);	 
	                }
           		   break;
           	   }
            }
        } else if (e.getActionCommand().equals(TDSLanguageUtils.getMessage("REPARACIONS_BOTO_SORTIR"))) {
   			this.setVisible(false);
   			try {
				remotS1 = new ClientRMI();
				remotS1.connecta();
	        	panelInicial = new S1PanelInicial(frameReparacions, remotS1.getInterficie(), usuari);
	        	frameReparacions.setContentPane(panelInicial);
	        	frameReparacions.pack();
			} catch (ExcepcioClientRMI e1) {
				e1.printStackTrace();
			}

            //frameReparacions.dispose();
        }
    }
}
